package oo

import (
	"elegantGo/chapter17/controller/response"
	"elegantGo/chapter17/oo/user"
	"time"
)

type VipUser interface {
	GetVipResourceDownloadTimes() int
	SetVipResourceDownloadTimes(v int)
	GetVipStartTime() *time.Time
	SetVipStartTime(*time.Time)
	GetVipEndTime() *time.Time
	SetVipEndTime(*time.Time)
}

type baseVipUser struct {
	baseUser
	vipStartTime             *time.Time
	vipEndTime               *time.Time
	vipResourceDownloadTimes user.VipResourceDownloadTimes
}

func (oo *baseVipUser) VipExpired() bool {
	return oo.vipEndTime.Before(time.Now())
}

func (oo *baseVipUser) GetVipStartTime() *time.Time {
	return oo.vipStartTime
}

func (oo *baseVipUser) SetVipStartTime(v *time.Time) {
	oo.vipStartTime = v
}

func (oo *baseVipUser) GetVipEndTime() *time.Time {
	return oo.vipEndTime
}

func (oo *baseVipUser) SetVipEndTime(v *time.Time) {
	oo.vipEndTime = v
}

func (oo *baseVipUser) GetVipResourceDownloadTimes() int {
	return oo.vipResourceDownloadTimes.Value()
}

func (oo *baseVipUser) SetVipResourceDownloadTimes(v int) {
	oo.vipResourceDownloadTimes.SetValue(v)
}

func (oo *baseVipUser) Mapper() *response.User {
	if oo == nil {
		return nil
	}

	respArticle := oo.baseUser.Mapper()
	respArticle.VipStartTime = oo.vipStartTime
	respArticle.VipEndTime = oo.vipEndTime
	vipExpired := oo.VipExpired()
	respArticle.VipExpired = &vipExpired
	respArticle.VipResourceDownloadTimes = oo.vipResourceDownloadTimes.ValuePtr()

	return respArticle
}

type NormalUser struct {
	baseUser
}

type VipMonthlyUser struct {
	baseVipUser
}

type VipYearlyUser struct {
	baseVipUser
	user.VipResourceDiscounter
}

type VipSuperYearlyUser struct {
	baseVipUser
	user.VipResourceDiscounter
}

type VipTwoYearlyUser struct {
	baseVipUser
}
